package com.zjitc.dao.Impl;

import com.zjitc.dao.SingletonTemplate;
import com.zjitc.dao.UserDao;
import com.zjitc.dao.UserRowMapper;
import com.zjitc.daomain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

@Component("userDao")
public class UserDaoImpl implements UserDao {
    private JdbcTemplate jdbcTemplate= SingletonTemplate.getJdbcTemplate();


    public void save() {
        System.out.println("User dao save");
        String sql="INSERT INTO users(NAME) VALUE(\"test\")";
        jdbcTemplate.execute(sql);

    }


    public User select(int id){
        String sql="select * from users where id=?;";
        User user=jdbcTemplate.queryForObject(sql,new UserRowMapper(),id);
        return user;
    }
}
